package com.mgface.zookeeper.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class CreateNode {

	public static void main(String[] args) throws Exception {
		CuratorFramework client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183")
				.sessionTimeoutMs(10_000)
				.namespace("curator")//指定隔离命名空间
				.retryPolicy(new ExponentialBackoffRetry(100, 3))//baseSleepTimeMs：初始sleep时间
				.build();
		client.start();
		System.out.println("启动完毕...");
		String newpath = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
				.forPath("/c11", "init".getBytes());
		System.out.println("生成的顺序节点:"+newpath);
		System.out.println(new String(client.getData().forPath(newpath)));

	}

}
